package com.jackrain.nea.wms.utils;

import com.alibaba.fastjson.JSONObject;
import com.jackrain.nea.exception.NDSException;
import com.jackrain.nea.util.ApplicationContextHandle;
import com.jackrain.nea.web.mapper.SqlMapper;
import com.jackrain.nea.web.service.QueryService;
import com.jackrain.nea.web.utils.ObjectToUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;

@Component
public class WmsQueryService {

    private static final Logger log = LoggerFactory.getLogger(WmsQueryService.class);

    public WmsQueryService() {
    }

    public Long commandInsert(HashMap map) {
        SqlMapper sqlMapper = (SqlMapper) ApplicationContextHandle.getBean(SqlMapper.class);
        String tableName = com.jackrain.nea.web.utils.ObjectToUtil.getString(map.get("tableName"), "");
        if (ObjectToUtil.isNullOREmpty(tableName)) {
            throw new NDSException("tableName不能为空！");
        } else if (map.get("insertKeys") == null) {
            throw new NDSException("insertKeys不能为null！");
        } else {

            JSONObject insertKeys = (JSONObject) map.get("insertKeys");
            sqlMapper.insert(tableName, insertKeys);
            return insertKeys.getLong("ID");

        }
    }


}
